package com.kws.tool.controller;

import com.kws.common.core.domain.R;
import com.kws.system.api.domain.*;
import com.kws.tool.config.WebSocketServer;
import com.kws.tool.service.ContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author :yxy
 * @date : 2024/11/26
 */
@RequestMapping("/contract")
@RestController
@Api(value = "合同功能", tags = "合同功能")
public class ContractController {

    @Autowired
    private ContractService contractService;
    @ApiOperation("上传文件模板")
    @PostMapping("/saveContract")
    public R<EQBTemplateVo> saveContract(@RequestParam("file") MultipartFile file){
        EQBTemplateVo eqbDto = contractService.saveContract(file);

        return R.ok(eqbDto);
    }

    @ApiOperation("删除文件模板")
    @PostMapping("/deleteContract/{docTemplateId}")
    public R deleteContract(@PathVariable String docTemplateId){
        Boolean flag = contractService.deleteContract(docTemplateId);
        return R.ok(flag);
    }

    @ApiOperation("根据模板id查询模板控件")
    @GetMapping("/getComponentsInfo/{docTemplateId}")
    public R<ResultDto> getComponentsInfo(@PathVariable String docTemplateId){
        ResultDto resultDto = contractService.getComponentsInfo(docTemplateId);
        return R.ok(resultDto);
    }

    @ApiOperation("填充模板--合同金额、甲方、乙方")
    @PostMapping("/createByDocTemplate")
    public R<ResultDto> createByDocTemplate(@RequestBody CreateTemplate createTemplate){
        ResultDto resultDto = contractService.createByDocTemplate(createTemplate);
        return R.ok(resultDto);
    }

    @ApiOperation("创建合同并发起")
    @PostMapping("/createContract")
    public R<ResultDto> createContract(@RequestBody CreateContractDto createContractPo){
        ResultDto resultDto = contractService.createContract(createContractPo);
        return R.ok(resultDto);
    }

    @ApiOperation("查看合同--免登录，任何人可查看")
    @GetMapping("/signViewLink/{signFlowId}")
    public R<ResultDto> signViewLink(@PathVariable String signFlowId){
        ResultDto resultDto = contractService.signViewLink(signFlowId);
        return R.ok(resultDto);
    }


    @ApiOperation("获取签署链接")
    @PostMapping("/signLink")
    public R<ResultDto> signLink(@RequestBody QuerySignUrlRq querySignUrlRq){
        ResultDto resultDto = contractService.signLink(querySignUrlRq);
        return R.ok(resultDto);
    }

    @ApiOperation("文件下载地址")
    @GetMapping("/fileDownloadUrl/{signFlowId}")
    public R<ResultDto> fileDownloadUrl(@PathVariable String signFlowId){
        ResultDto resultDto = contractService.fileDownloadUrl(signFlowId);
        return R.ok(resultDto);
    }

    @ApiOperation("查询签署流程详情")
    @GetMapping("/signFlowDetail/{signFlowId}")
    public R<ResultDto> signFlowDetail(@PathVariable String signFlowId){
        ResultDto resultDto = contractService.signFlowDetail(signFlowId);
        return R.ok(resultDto);
    }

    @ApiOperation("查询签署流程列表")
    @PostMapping("/signFlowList")
    public R<ResultDto> signFlowList(@RequestBody SignFlowRq signFlowRq){
        ResultDto resultDto = contractService.signFlowList(signFlowRq);
        return R.ok(resultDto);
    }

    @ApiOperation("撤销签署流程")
    @PostMapping("/signFlowRevoke")
    public R<ResultDto> signFlowRevoke(@RequestBody SignFlowRevoke signFlowRevoke){
        ResultDto resultDto = contractService.signFlowRevoke(signFlowRevoke);
        return R.ok(resultDto);
    }
}
